<template>
  <div v-if="parentData">
    <!-- 第二楼层 -->
    <div class="parent">
      <parent
        @replyParent="replyComment"
        :parentData="parentData.parent"
        v-if="parentData.parent"
        :level="level-1"
      />
      <div class="parentItem">
        <div class="info">
          <div class="nickname">{{parentData.account.nickname}}</div>
          <div class="date">{{newDate}}</div>
          <div class="floor">{{level}}楼</div>
        </div>
        <div class="content_reply">
          <div class="content">
            {{parentData.content}}
            <div class="imgList" v-if="parentData.pics">
              <div class="imgItem" v-for="(item,index) in parentData.pics" :key="index">
                <img class="img" :src="$axios.defaults.baseURL+item.url" alt />
              </div>
            </div>
          </div>
          <div class="reply" @click="parentReply(parentData)">回复</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "parent",
  props: {
    parentData: Object,
    level: Number
  },
  computed: {
    newDate() {
      return this.$moment(this.parentData.created_at).format(
        "YYYY-MM-DD hh:mm"
      );
    }
  },
  methods: {
    parentReply(parent) {
      this.$emit("replyParent", parent);
    },
    // 回复评论
    replyComment(parent) {
      this.$emit("replyParent", parent);
    }
  }
};
</script>
<style lang="less" scoped>
.parent {
  border: 1px solid #ddd;
  background: #f9f9f9;
  margin: 2px;
  .parentItem {
    padding: 8px 8px 0 8px;
    .info {
      display: flex;
      align-items: center;
      font-size: 12px;
      color: #666;
      padding-bottom: 6px;
      .nickname {
        padding-right: 5px;
      }
      .date {
        color: #999;
      }
      .floor {
        flex: 1;
        text-align: right;
      }
    }
  }
  .content_reply {
    .content {
      padding: 6px 0 0;
      /deep/ .imgList {
        display: flex;
        margin-top: 6px;
        .imgItem {
          padding: 6px;
          margin-top: 2px;
          margin-right: 2px;
          width: 90px;
          height: 90px;
          border: 1px dashed #ddd;
          border-radius: 4px;
          .img {
            width: 100%;
            height: 100%;
            object-fit: cover;
          }
        }
      }
    }
    .reply {
      padding: 3px 0;
      font-size: 12px;
      text-align: right;
      color: #1e50a2;
      opacity: 0;
    }
    &:hover .reply {
      opacity: 1;
      cursor: pointer;
    }
  }
}
</style>